<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>git | 雨落</title>
  <meta name="description" content="1、版本回退 查看提交历史,拿到回退的目标版本的commit_id 1git log  Git本地版本回退 12git reset --hard commit_idgit log  &#x2F;&#x2F; 查看本地版本的最新版本是不是刚才回退到的那个版本，如果是，那说明版本回退成功  推送到远程 1git push   &#x2F;&#x2F; 如果推送不了，使用强推  git push -f    2、切换分支报错error: pa">
<meta property="og:type" content="article">
<meta property="og:title" content="git">
<meta property="og:url" content="https://gitee.com/Yu-Luoboke/2020/12/11/git/index.html">
<meta property="og:site_name" content="雨落">
<meta property="og:description" content="1、版本回退 查看提交历史,拿到回退的目标版本的commit_id 1git log  Git本地版本回退 12git reset --hard commit_idgit log  &#x2F;&#x2F; 查看本地版本的最新版本是不是刚才回退到的那个版本，如果是，那说明版本回退成功  推送到远程 1git push   &#x2F;&#x2F; 如果推送不了，使用强推  git push -f    2、切换分支报错error: pa">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-12-11T01:14:36.000Z">
<meta property="article:modified_time" content="2023-04-14T05:26:02.952Z">
<meta property="article:author" content="lianghongming">
<meta name="twitter:card" content="summary">
  <!-- Canonical links -->
  <link rel="canonical" href="https://gitee.com/Yu-Luoboke/2020/12/11/git/index.html">
  
    <link rel="alternate" href="/atom.xml" title="雨落" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 5.2.0"></head>


<body class="main-center" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="http://yu-luoboke.gitee.io/blog" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">雨落</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">前端开发-奋斗青年</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> GuangZhou, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav menu-highlight">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="http://yu-luoboke.gitee.io/blog" target="_blank" title="Github" ><i class="icon icon-github"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Git/">Git</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/HTML-CSS/">HTML + CSS</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/JVM%EF%BC%88Java%E8%99%9A%E6%8B%9F%E6%9C%BA%EF%BC%89-%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6%E7%AE%97%E6%B3%95/">JVM（Java虚拟机）-垃圾回收算法</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Node/">Node</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Project/">Project</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/React/">React</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/SVN/">SVN</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Vue-typescript/">Vue-typescript</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/gitee/">gitee</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/iOS/">iOS</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/js/">js</a><span class="category-list-count">12</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/vue/">vue</a><span class="category-list-count">13</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/web-serve%E9%9D%99%E6%80%81%E8%B5%84%E6%BA%90%E6%9C%8D%E5%8A%A1%E5%99%A8/">web serve静态资源服务器</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/webpack/">webpack</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E5%89%8D%E7%AB%AF%E8%87%AA%E5%8A%A8%E5%8C%96/">前端自动化</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E5%B0%8F%E7%A8%8B%E5%BA%8F/">小程序</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E7%A7%BB%E5%8A%A8%E7%AB%AF/">移动端</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E7%BB%8F%E9%AA%8C/">经验</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a><span class="category-list-count">4</span></li></ul>
    </div>
  </div>


    
      

    
      
    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2024/04/">四月 2024</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/11/">十一月 2023</a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/09/">九月 2023</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/12/">十二月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/08/">八月 2022</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/07/">七月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/06/">六月 2022</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/04/">四月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/01/">一月 2022</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/12/">十二月 2021</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/11/">十一月 2021</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/10/">十月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/04/">四月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/03/">三月 2021</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/02/">二月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2021/01/">一月 2021</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/12/">十二月 2020</a><span class="archive-list-count">15</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/HTML-CSS/">HTML + CSS</a>
              </p>
              <p class="item-title">
                <a href="/blog/2024/04/15/%E6%8B%96%E5%8A%A8%E5%92%8C%E7%82%B9%E5%87%BB%E5%BC%B9%E7%AA%97/" class="title">拖动和点击弹窗</a>
              </p>
              <p class="item-date">
                <time datetime="2024-04-15T12:22:06.000Z" itemprop="datePublished">2024-04-15</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
              </p>
              <p class="item-title">
                <a href="/blog/2023/11/29/html%E9%9D%A2%E8%AF%95%E9%A2%98/" class="title">html面试题</a>
              </p>
              <p class="item-date">
                <time datetime="2023-11-29T15:58:27.000Z" itemprop="datePublished">2023-11-29</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
              </p>
              <p class="item-title">
                <a href="/blog/2023/11/29/css%E9%9D%A2%E8%AF%95%E9%A2%98/" class="title">css面试题</a>
              </p>
              <p class="item-date">
                <time datetime="2023-11-29T15:57:17.000Z" itemprop="datePublished">2023-11-29</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
              </p>
              <p class="item-title">
                <a href="/blog/2023/11/29/js%E9%9D%A2%E8%AF%95%E9%A2%98/" class="title">js面试题</a>
              </p>
              <p class="item-date">
                <time datetime="2023-11-29T15:37:30.000Z" itemprop="datePublished">2023-11-29</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/%E9%9D%A2%E8%AF%95%E9%A2%98/">面试题</a>
              </p>
              <p class="item-title">
                <a href="/blog/2023/11/29/%E9%9D%A2%E8%AF%95%E9%A2%98/" class="title">面试题</a>
              </p>
              <p class="item-date">
                <time datetime="2023-11-29T15:29:49.000Z" itemprop="datePublished">2023-11-29</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<main class="main" role="main">
  <div class="content">
  <article id="post-git" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      git
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2020/12/11/git/" class="article-date">
	  <time datetime="2020-12-11T01:14:36.000Z" itemprop="datePublished">2020-12-11</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/Git/">Git</a>
  </span>

        

        

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2020/12/11/git/#comments" class="article-comment-link">评论</a></span>
        
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h3 id="1、版本回退"><a href="#1、版本回退" class="headerlink" title="1、版本回退"></a>1、版本回退</h3><ul>
<li><p>查看提交历史,拿到回退的目标版本的commit_id</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git log</span><br></pre></td></tr></table></figure>
</li>
<li><p>Git本地版本回退</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard commit_id</span><br><span class="line">git log  <span class="comment">// 查看本地版本的最新版本是不是刚才回退到的那个版本，如果是，那说明版本回退成功</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>推送到远程</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push   <span class="comment">// 如果推送不了，使用强推  git push -f</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="2、切换分支报错error-pathspec-‘master’-did-not-match-any-file-s-known-to-git"><a href="#2、切换分支报错error-pathspec-‘master’-did-not-match-any-file-s-known-to-git" class="headerlink" title="2、切换分支报错error: pathspec ‘master’ did not match any file(s) known to git"></a>2、切换分支报错error: pathspec ‘master’ did not match any file(s) known to git</h3><ul>
<li>git checkout 分支名 切花分支，无法切换，报错如上</li>
<li>原因：本地中没有对应的分支</li>
<li>解决方法：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git branch -a    <span class="comment">// 查看所有分支</span></span><br><span class="line">git fetch        <span class="comment">// 获取所有分支</span></span><br><span class="line">git chekcout 分支</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="3、本地分支重命名，重新推送到远程"><a href="#3、本地分支重命名，重新推送到远程" class="headerlink" title="3、本地分支重命名，重新推送到远程"></a>3、本地分支重命名，重新推送到远程</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 分支重命名</span></span><br><span class="line">git branch -m oldBranch newBranch</span><br><span class="line"></span><br><span class="line"><span class="comment">// 删除远程的 oldBranch</span></span><br><span class="line">git push origin --<span class="keyword">delete</span> 分支名(或者直接在 gitlab 上删除，推荐)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 将改名后的分支推送到远程</span></span><br><span class="line">git push --set-upstream origin newBranch</span><br></pre></td></tr></table></figure>

<h3 id="3、删除本地分支，删除远程分支，创建新的分支并推送"><a href="#3、删除本地分支，删除远程分支，创建新的分支并推送" class="headerlink" title="3、删除本地分支，删除远程分支，创建新的分支并推送"></a>3、删除本地分支，删除远程分支，创建新的分支并推送</h3><ul>
<li><p>删除本地分支：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch -D 分支名</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除远程分支：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push origin --<span class="keyword">delete</span> 分支名</span><br></pre></td></tr></table></figure>
</li>
<li><p>一般来说，删除分支后需要重新创建一个分支并推送上去</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout -b 新分支   <span class="comment">// 基于master创建新的分支</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>将新的分支推送到远程</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push</span><br></pre></td></tr></table></figure>

<p>但是报错了：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">fatal: The current branch sit has no upstream branch.</span><br><span class="line">To push the current branch and set the remote <span class="keyword">as</span> upstream, use</span><br><span class="line"></span><br><span class="line">    git push --set-upstream origin sit  <span class="comment">// 意思是：当前分支没有与远程分支关联，导致代码提交失败</span></span><br></pre></td></tr></table></figure>

<p>所以直接根据它的提示输入：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push --set-upstream origin 分支名</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="4、git-pull报错"><a href="#4、git-pull报错" class="headerlink" title="4、git pull报错"></a>4、git pull报错</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">There is no tracking information <span class="keyword">for</span> the current branch.</span><br><span class="line">Please specify which branch you want to merge <span class="keyword">with</span>.</span><br><span class="line">See git-pull(<span class="number">1</span>) <span class="keyword">for</span> details.</span><br><span class="line">    git pull &lt;remote&gt; &lt;branch&gt;</span><br><span class="line">If you wish to set tracking information <span class="keyword">for</span> <span class="built_in">this</span> branch you can <span class="keyword">do</span> so <span class="keyword">with</span>:</span><br><span class="line">    git branch --set-upstream-to=origin/&lt;branch&gt; master</span><br></pre></td></tr></table></figure>
<ul>
<li>解决方法：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch --set-upstream-to=origin/master  master </span><br></pre></td></tr></table></figure></li>
<li>最快的方法：如果是其它分支如：sit等，直接删除本地上的sit分支，然后重新切换分支<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git checkout sit  <span class="comment">// 删除分支后，重新拉取分支</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="5、回退git-add-回退git-commit"><a href="#5、回退git-add-回退git-commit" class="headerlink" title="5、回退git add , 回退git commit"></a>5、回退git add , 回退git commit</h3><ul>
<li><p>场景：撤销add</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">git add a.txt</span><br><span class="line">git status <span class="comment">// 查看暂缓区的文件</span></span><br><span class="line"><span class="comment">//On branch develop</span></span><br><span class="line"><span class="comment">//Changes to be committed:</span></span><br><span class="line"><span class="comment">// (use &quot;git restore --staged &lt;file&gt;...&quot; to unstage)</span></span><br><span class="line"><span class="comment">//        new file:   a.txt</span></span><br><span class="line">git restore --staged a.txt <span class="comment">// 根据上面的提示，将单个文件取消add</span></span><br><span class="line">git reset HEAD <span class="comment">// 将多个文件取消add，HEAD不是表示commit的值，就是一个单词：HEAD</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>场景，撤销commit</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git add .</span><br><span class="line">git commit -m <span class="string">&#x27;测试&#x27;</span> <span class="comment">// 当前commit (aaaaaa)</span></span><br><span class="line">git log <span class="comment">// 查看HEAD</span></span><br><span class="line">git reset --soft HEAD <span class="comment">// HEAD：上一个commit(bbbbb),这样就能将本次commit的内容给恢复到暂缓区</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>场景：撤销commit和add（当然，也可以将上面两个步骤依次执行也能实现改场景）</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset --mixed HEAD <span class="comment">// HEAD: 上一个commit值，撤销commit和add，并且保留修改的内容</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>场景：撤销commit和add，并且删除改动</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git reset --hard HEAD <span class="comment">// HEAD: commit值</span></span><br></pre></td></tr></table></figure>


</li>
</ul>
<h3 id="6、取消分支合并"><a href="#6、取消分支合并" class="headerlink" title="6、取消分支合并"></a>6、取消分支合并</h3><ul>
<li>场景：合并分支后想取消合并<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git merge --abort</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="7、给分支添加描述"><a href="#7、给分支添加描述" class="headerlink" title="7、给分支添加描述"></a>7、给分支添加描述</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 给分支添加描述</span></span><br><span class="line">git config branch.分支.description <span class="string">&quot;这是分支&quot;</span></span><br><span class="line"><span class="comment">// 查看分支描述</span></span><br><span class="line">git config branch.分支.description  <span class="comment">// 查看单个分支</span></span><br><span class="line">git br <span class="comment">// 查看所有分支描述</span></span><br></pre></td></tr></table></figure>

<h3 id="8、本地分支和远程分支都被误删了，如何恢复，本次案例已test分支为例，可以在任何分支进行操作"><a href="#8、本地分支和远程分支都被误删了，如何恢复，本次案例已test分支为例，可以在任何分支进行操作" class="headerlink" title="8、本地分支和远程分支都被误删了，如何恢复，本次案例已test分支为例，可以在任何分支进行操作"></a>8、本地分支和远程分支都被误删了，如何恢复，本次案例已test分支为例，可以在任何分支进行操作</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 查看reflog，找到最后一次commitid</span></span><br><span class="line">git reflog --date=iso  <span class="comment">// 与git log的区别：git log 是查看当前分支的commitid  --date=iso:表示以标准时间格式展示</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// PS C:\Users\Administrator\Desktop\新建文件夹 (2)\git&gt; git reflog --date=iso</span></span><br><span class="line"><span class="comment">// 6906c3a (HEAD -&gt; master, origin/master, origin/HEAD) HEAD@&#123;2021-04-20 19:15:32 +0800&#125;: checkout: moving from test to master</span></span><br><span class="line"><span class="comment">// b1606d9 HEAD@&#123;2021-04-20 19:14:52 +0800&#125;: commit: 恢复删除的远程分支</span></span><br><span class="line"><span class="comment">// 6906c3a (HEAD -&gt; master, origin/master, origin/HEAD) HEAD@&#123;2021-04-20 19:14:12 +0800&#125;: checkout: moving from master to test</span></span><br><span class="line"><span class="comment">// 6906c3a (HEAD -&gt; master, origin/master, origin/HEAD) HEAD@&#123;2021-04-20 19:11:58 +0800&#125;: checkout: moving from test to master</span></span><br><span class="line"><span class="comment">// 6906c3a (HEAD -&gt; master, origin/master, origin/HEAD) HEAD@&#123;2021-04-20 19:11:18 +0800&#125;: checkout: moving from master to test</span></span><br><span class="line"><span class="comment">// 6906c3a (HEAD -&gt; master, origin/master, origin/HEAD) HEAD@&#123;2021-04-20 19:10:48 +0800&#125;: clone: from https://gitee.com/Yu-Luoboke/git.git</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 从上面日志可以看出，test分支的最后一次commit是b1606d9,所以用这个commitid来恢复分支</span></span><br><span class="line"><span class="comment">// 重新切出分支</span></span><br><span class="line">git checkout -b test b1606d9</span><br><span class="line"></span><br><span class="line">git branch   <span class="comment">// 发现删除的test分支已经恢复，重新推送到远程即可</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="将某一次commit的内容合并到指定分支"><a href="#将某一次commit的内容合并到指定分支" class="headerlink" title="将某一次commit的内容合并到指定分支"></a>将某一次commit的内容合并到指定分支</h3><ul>
<li><p>a 分支有5个 commit 记录，commit1，commit2，commit3，commit4，commit5</p>
</li>
<li><p>需要将 commit2，commit4 单独合并到 b 分支</p>
</li>
<li><p>操作步骤如下：</p>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 执行命令：</span></span><br><span class="line">git cherry-pick commit4_id （发现冲突解决冲突）</span><br><span class="line"></span><br><span class="line"><span class="comment">// 解决完冲突后，继续合并</span></span><br><span class="line">git cherry-pick commit2_id （有冲突则解决冲突）</span><br><span class="line"></span><br><span class="line"><span class="comment">// 合并结束</span></span><br></pre></td></tr></table></figure>

<h3 id="9、yarn安装依赖时报-unable-to-verify-the-first-certificate-错误"><a href="#9、yarn安装依赖时报-unable-to-verify-the-first-certificate-错误" class="headerlink" title="9、yarn安装依赖时报 unable to verify the first certificate 错误"></a>9、yarn安装依赖时报 <code>unable to verify the first certificate</code> 错误</h3><ul>
<li>报错信息如下：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">D:\Code\Web\StudyOrTest\electronStudy&gt; yarn add axios</span><br><span class="line">yarn add v1<span class="number">.22</span><span class="number">.10</span></span><br><span class="line">[<span class="number">1</span>/<span class="number">4</span>] Resolving packages...</span><br><span class="line">error An unexpected error occurred: <span class="string">&quot;https://registry.yarnpkg.com/webpack: unable to verify the first certificate&quot;</span>.</span><br><span class="line">info If you think <span class="built_in">this</span> is a bug, please open a bug report <span class="keyword">with</span> the information provided <span class="keyword">in</span> <span class="string">&quot;D:\\Code\\Web\\StudyOrTest\\electronStudy\\yarn-error.log&quot;</span>.</span><br></pre></td></tr></table></figure></li>
<li>错误原因分析：<ul>
<li>可能是下载源的问题，但是切换到淘宝镜像后还是无法解决</li>
<li>最终查资料得知，这是HTTPS证书验证失败导致的</li>
</ul>
</li>
<li>解决方法：<ul>
<li>将yarn配置中strict-ssl 设置为 flase，因为：值为true，代表着需要验证HTTPS证书，设置为false，则会跳过HTTPS证书验证<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 步骤如下</span></span><br><span class="line"><span class="comment">// 1、查看yarn的配置清单：yarn config list</span></span><br><span class="line">D:\Code\Web\StudyOrTest\electronStudy&gt; yarn config list</span><br><span class="line">yarn config v1<span class="number">.22</span><span class="number">.10</span></span><br><span class="line">info yarn config</span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">&#x27;version-tag-prefix&#x27;</span>: <span class="string">&#x27;v&#x27;</span>,</span><br><span class="line">  <span class="string">&#x27;version-git-tag&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="string">&#x27;version-commit-hooks&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="string">&#x27;version-git-sign&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">  <span class="string">&#x27;version-git-message&#x27;</span>: <span class="string">&#x27;v%s&#x27;</span>,</span><br><span class="line">  <span class="string">&#x27;init-version&#x27;</span>: <span class="string">&#x27;1.0.0&#x27;</span>,</span><br><span class="line">  <span class="string">&#x27;init-license&#x27;</span>: <span class="string">&#x27;MIT&#x27;</span>,</span><br><span class="line">  <span class="string">&#x27;bin-links&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="string">&#x27;ignore-scripts&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">  <span class="string">&#x27;ignore-optional&#x27;</span>: <span class="literal">false</span>,</span><br><span class="line">  <span class="string">&#x27;strict-ssl&#x27;</span>: <span class="literal">true</span>, <span class="comment">// 这里的初始值为true，将这里的值修改为false，则解决问题</span></span><br><span class="line">  <span class="string">&#x27;user-agent&#x27;</span>: <span class="string">&#x27;yarn/1.22.10 npm/? node/v12.18.3 win32 x64&#x27;</span>,</span><br><span class="line">  ELECTRON_MIRROR: <span class="string">&#x27;https://cdn.npm.taobao.org/dist/electron/&#x27;</span>,</span><br><span class="line">  lastUpdateCheck: <span class="number">1605235165526</span>,</span><br><span class="line">  <span class="string">&#x27;sass-binary-site&#x27;</span>: <span class="string">&#x27;http://npm.taobao.org/mirrors/node-sass&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line">info npm config</span><br><span class="line">&#123;</span><br><span class="line">  tb_registry: <span class="string">&#x27;https://registry.npm.taobao.org&#x27;</span>,</span><br><span class="line">  registry: <span class="string">&#x27;https://registry.npm.taobao.org/&#x27;</span>,</span><br><span class="line">  disturl: <span class="string">&#x27;https://npm.taobao.org/dist&#x27;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li>通过命令：yarn config set strict-ssl false 即可将strict-ssl的值设置为false</li>
<li>查看strict-ssl的值是否设置正确：可以使用yarn config list，也可以使用yarn config get strict-ssl 查看</li>
<li>设置完成之后，重新安装依赖，发现已经可以正常安装了</li>
<li>如果发现npm安装依赖也是如此，那么也是使用上面这种方法进行设置即可<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm config list  <span class="comment">// 查看npm配置</span></span><br><span class="line">npm config set strict-ssl <span class="literal">false</span> <span class="comment">// 设置属性的值为false</span></span><br></pre></td></tr></table></figure></li>
</ul>

      
    </div>
    <div class="article-footer">
      <!-- <blockquote class="mt-2x"> -->
  <!-- <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="https://gitee.com/Yu-Luoboke/2020/12/11/git/" title="git" target="_blank" rel="external">https://gitee.com/Yu-Luoboke/2020/12/11/git/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul> -->
<!-- </blockquote> -->


<!-- <div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="http://yu-luoboke.gitee.io/blog" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="http://yu-luoboke.gitee.io/blog" target="_blank"><span class="text-dark">雨落</span><small class="ml-1x">前端开发-奋斗青年</small></a></h3>
        <div>前端经验总结。</div>
      </div>
    </figure>
  </div>
</div> -->


    </div>
  </article>
  
    

  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2020/12/11/ios%E5%85%BC%E5%AE%B9%E6%80%A7%E9%97%AE%E9%A2%98/" title="ios兼容性问题"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2020/12/11/svn/" title="svn"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
  </ul>
  
  
  
  <div class="bar-right">
    
  </div>
  </div>
</nav>
  


</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="http://yu-luoboke.gitee.io/blog" target="_blank" title="Github" ><i class="icon icon-github"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2024 lianghongming
        
        <div class="publishby">
        	Theme by <a href="https://gitee.com/Yu-Luoboke/blog" target="_blank"> blog </a>base on <a href="https://gitee.com/Yu-Luoboke/blog" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/blog/js/plugin.min.js"></script>


<script src="/blog/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/blog/js/insight.js"></script>






   









</body>
</html>